# -*- coding: utf-8 -*-
# 智兔APP客户看板-客户流失统计
# author： 郭瑞玲
# create_time: 2022-03-09 16:00:00

from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.dwd.tab.dwd_dependent_hi.dwd_tab_barscan_arrival_base_hi_05 import jms_dwd__dwd_tab_barscan_arrival_base_hi_05
from jms.dwd.tab.dwd_dependent_hi.dwd_tab_barscan_send_base_hi_05 import jms_dwd__dwd_tab_barscan_send_base_hi_05
from jms.dwd.tab.dwd_dependent_hi.dwd_tab_barscan_deliver_base_hi_05 import jms_dwd__dwd_tab_barscan_deliver_base_hi_05
from jms.dwd.tab.dwd_dependent_hi.dwd_tab_barscan_collect_base_hi_05 import jms_dwd__dwd_tab_barscan_collect_base_hi_05
from jms.dwd.tab.dwd_dependent_hi.dwd_tab_barscan_sign_base_hi_05 import jms_dwd__dwd_tab_barscan_sign_base_hi_05

# 中心滞留导数
jms_dm__dm_center_detention_detail_dt = SparkSqlOperator(
    task_id='jms_dm__dm_center_detention_detail_dt',
    task_concurrency=1,
    pool_slots=4,
    master='yarn',
    execution_timeout = timedelta(minutes=30),
    email=['guoruiling@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_center_detention_detail_dt_{{ execution_date | cst_ds }}',
    sql='jms/dm/dm_center_detention_detail_dt/execute.hql',
    driver_memory='8G',
    driver_cores=4,
    executor_cores=4,
    executor_memory='6G',
    num_executors=30,
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors': 40,  # 动态资源最大扩容 Executor 数
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.executor.memoryOverhead': '2G',  # 堆外内存
        'spark.hadoop.hive.exec.dynamic.partition.mode': 'nonstrict', # 动态分区
        'spark.hadoop.hive.exec.dynamic.partition': 'true',
        'spark.sql.shuffle.partitions': 360,
        'spark.yarn.maxAppAttempts':1
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 200,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 200,  # 每天生成 20 个分区
              },
    yarn_queue='pro',
)


jms_dm__dm_center_detention_detail_dt << [
    jms_dwd__dwd_tab_barscan_arrival_base_hi_05,
    jms_dwd__dwd_tab_barscan_send_base_hi_05,
    jms_dwd__dwd_tab_barscan_deliver_base_hi_05,
    jms_dwd__dwd_tab_barscan_collect_base_hi_05,
    jms_dwd__dwd_tab_barscan_sign_base_hi_05
]
